<template>
  <div class="recommend-lunbo">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(item, index) in recommends" :key="index">
        <img class="swiper-image" :src="item.imageUrl">
      </swiper-slide>
      <!-- <div class="swiper-pagination" slot="pagination"></div> -->
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script type="text/javascript">
// 获取轮播数据
import { getBanner } from '../../../api/recommend'
// 200验证
import { ERR_OK } from '../../../common/js/common'
export default {
  data () {
    return {
      // 轮播歌数据
      recommends: [],
      swiperOption: {
        loop: true,
        autoplay: 1500,
        pagination: '.swiper-pagination',
        initialSlide: 1,
        // 用户操作swiper之后，是否禁止autoplay.默认为true：停止。
        autoplayDisableOnInteraction: false,
        // 拖动释放时不会输出信息，阻止click冒泡。拖动Swiper时阻止click事件。
        preventLinksPropagation: true
      }
    }
  },
  methods: {
    // 获取轮播数据
    _getBanner () {
      getBanner().then((res) => {
        if (res.status === ERR_OK) {
          this.recommends = res.data.banners
          // console.log(this.recommends)
        }
      })
    }
  },
  created () {
    this._getBanner()
    // this._getDiscList()
  }
}

</script>

<style lang="less" scoped>
.recommend-lunbo {
  padding-top: 88px;
  overflow: hidden;
  width: 100%;
  height: 0;
  padding-bottom: 38.25%;
}
.swiper-image {
  width: 100%
}
</style>
